<?php
//查看订单文件的员工页面
$document_root = $_SERVER['DOCUMENT_ROOT'];
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Bob`s Auto Parts - Order Results-Bob的汽车配件-订单结果</title>

</head>

<body>
    <h1>Bob`s Auto Parts - Bob的汽车配件</h1>
    <h2>Customer Orders - 客户订单</h2>
<?php

    echo "<h1>查看订单是否存在</h1>";
    if (file_exists("$document_root/orders/orders.txt")) {
        echo "有订单<br />";
    } else {
        echo "没有订单<br />";
    }

    echo "<h1>确定文件大小</h1>";
    echo filesize("$document_root/orders/orders.txt")."字节<br />";


    @$fp=fopen("$document_root/orders/orders.txt",'rb');
    flock($fp,LOCK_SH);//阅读文件的时候锁定
    
    if(!$fp) {//如果没有数据， 抛出提示
        echo "<p><strong>No orders pending.<br />
        Please try again later.</strong></p>";
        exit;
    }
    
    while (!feof($fp)) {//读完文件为true
        $order = fgets($fp);//每次读一行内容
        //$order = fgetcsv($fp, 0,"\t");
        echo htmlspecialchars($order)."<br />";
        //echo $order."<br />";
    }
    flock($fp,LOCK_UN);//解除锁定
    fclose($fp);

?>

</body>
</html>